<link rel="stylesheet" type="text/css" href="/static/DataTables1.10.18/DataTables-1.10.18/css/dataTables.bootstrap.min.css"/>
<script type="text/javascript" src="/static/DataTables1.10.18/DataTables-1.10.18/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/DataTables1.10.18/DataTables-1.10.18/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/DataTables1.10.18/Buttons-1.5.4/css/buttons.dataTables.css">
<link rel="stylesheet" type="text/css" href="/static/DataTables1.10.18/Buttons-1.5.4/css/buttons.bootstrap.css">
<script src="/static/DataTables1.10.18/Buttons-1.5.4/js/dataTables.buttons.min.js"></script>
<script src="/static/DataTables1.10.18/Buttons-1.5.4/js/buttons.bootstrap.js"></script>
<script src="/static/DataTables1.10.18/JSZip-2.5.0/jszip.min.js"></script>
<script src="/static/DataTables1.10.18/Buttons-1.5.4/js/buttons.html5.min.js"></script>

<style>
.dataTable td {padding: 2px !important;}
table.dataTable thead tr:nth-child(1) td {padding-right: 30px !important;}
table.dataTable thead .sorting:after, table.dataTable thead .sorting_asc:after, table.dataTable thead .sorting_desc:after, table.dataTable thead .sorting_asc_disabled:after, table.dataTable thead .sorting_desc_disabled:after
{ bottom: 2px;}
#tbl tbody .statusN td:nth-child(3){cursor: pointer;color: #0a6aa1}
#tbl tbody .statusA td:nth-child(3){cursor: not-allowed;}
#tbl tbody .statusD td:nth-child(3){cursor: not-allowed;}
#tbl tbody .statusA td:nth-child(5){color:green;font-weight: bold;background-color: rgba(177,255,168,0.58)}
#tbl tbody .statusD td:nth-child(5){color:orange;font-weight: bold; background-color: rgba(255,139,0,0.30)}
#tbl tbody td:nth-child(9){word-break: break-all;}
#tbl_wrapper .btn-group {margin-left: 10px}
</style>

<div style="margin: 10px;">
<div class="panel panel-default " style="padding: 5px;">
  此界面列出您已创建的所有分类。您只能更新在此服务器上创建的未经验证的分类。<br>
  状态：N：未验证，A：激活，D：弃用/拒绝<br>
  这些分类在EcoTaxoServer上验证之前，在其他Ecotaxa实例上不可见。<br>
  建议在进行更改之前同步。
</div>

<button type="button" onclick="DoSync('Y')" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> 与EcotaxaServer同步</button>
<button type="button" onclick="NewTaxon()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> 创建分类</button>
<a href="{{ g.taxoserver_url }}/browsetaxo/" class="btn btn-primary"><span class="glyphicon glyphicon-link"></span> 在EcotaxoServer上浏览全部分类</a>
  {{ BackProjectBtn|safe }}
</div>

<table id="tbl" style="width:100%" class="table table-striped table-bordered" >
<thead>
  <tr><td>ID</td><td>上层ID</td><td>显示名</td><td>类型</td><td>状态</td>
  <td>创建者</td><td>源ID</td><td>创建日期</td><td>最新更新</td><td>谱系</td>
  </tr>
</thead>
<tbody>
{% for l in lst %}
  <tr class="status{{ l.taxostatus }}"><td>{{l.id}}</td><td>{{l.parent_id}}</td><td>{{l.name}}</td><td>{{l.taxotype}}</td><td>{{l.taxostatus}}</td>
  <td>{{l.creator_email or ''}}</td><td>{{l.id_source or ''}}</td><td>{{l.creation_datetime or ''}}</td><td>{{l.lastupdate_datetime}}</td><td>{{l.tree.replace('>',' > ')}}</td>
  </tr>
{% endfor %}
</tbody>
</table>


<script>
function DoSync(UpdateStat) {
  var params={};
  if (UpdateStat==='Y')
    params.updatestat='Y';
  At2PopupWaitOpenLoad(1,"/taxo/dosync","EcotaxoServer Synchronisation",params);
}
function NewTaxon() {
  At2PopupWaitOpenLoad(0,"/taxo/edit/0","Create new taxon");
}

$(document).ready(function() {

    var table=$('#tbl').DataTable( {
        scrollY:        '70vh',
        scrollCollapse: true,
        paging: false,
        orderCellsTop: true,
        buttons: ['copy', 'csv', 'excel'],
        dom: 'Bfrtip',
        orderMulti: false,
        ordering: false,
        columnDefs: [
           { width:'40px', targets: 0 }
          ,{ width:'60px', targets: 1 }
          ,{ width:'30px', targets: 3 }
          ,{ width:'30px', targets: 4 }
        ]
    });


    $('#tbl tbody').on('click','.statusN td:nth-child(3)',function () {
      var taxoid=$(this).closest('tr').find('td:nth-child(1)').text();
      At2PopupWaitOpenLoad(0,"/taxo/edit/"+taxoid,"Edit taxon "+taxoid);
    });
} );


</script>